package com.hxkj.utils.mapper;


import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.FreeMarker;
import com.hxkj.domain.po.Leaflet;
import com.hxkj.entity.vo.ResultMessage;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zzx on 2017/8/27.
 */
public class ArticleMapper {


    /**
     * 文章模板Map 组装类
     * @param article
     * @return FreeMarker
     */
    public static FreeMarker articMapper(Article article) {
        FreeMarker  model = new   FreeMarker();
        Map<String, Object> maps = new HashMap<>();
        maps.put("articleId" ,article.getArticleId());
        maps.put("headline" ,article.getHeadline());
        maps.put("subhead" ,article.getSubhead());
        maps.put("imgUrl" ,article.getImgUrl());
        maps.put("seoHeadline" ,article.getSeoHeadline());
        maps.put("seoKeyword" ,article.getSeoKeyword());
        maps.put("seoDescribe" ,article.getSeoDescribe());
        maps.put("source" ,article.getSource());
        maps.put("sourceLink" ,article.getSourceLink());
        maps.put("externalLink" ,article.getExternalLink());
        maps.put("columnId" ,article.getArticleId());
        maps.put("locationLevel" ,article.getLocationLevel());
        maps.put("heat" ,article.getHeat());
        maps.put("author" ,article.getAuthor());
        maps.put("summary" ,article.getSummary());
        maps.put("detail" ,article.getDetail());
        maps.put("evaluate" ,article.getEvaluate());
        maps.put("browse" ,article.getBrowse());
        maps.put("comment" ,article.getComment());
        maps.put("createTime" ,article.getCreateTime());
        maps.put("soldOldTime" ,article.getSoldOldTime());
        maps.put("updateTime" ,article.getUpdateTime());
        maps.put("auditType" ,article.getAuditType());
        maps.put("accessoryName" ,article.getAccessoryName());
        maps.put("accessoryUrl" ,article.getAccessoryUrl());
        maps.put("accessoryRemark" ,article.getAccessoryRemark());
        //maps.put("webName" ,article.getWebName());

        //装载数据模型
        model.setSiteId(article.getSiteId());
        model.setChannelId(String.valueOf(article.getColumnId()));
        model.setTempletId(article.getTempletId());
        model.setMaps(maps);
        return model;
    }

    /**
     * 单页模板Map 组装类
     * @param leaflet
     * @return FreeMarker
     */
    public static FreeMarker leafletMapper(Leaflet leaflet) {
        FreeMarker  model = new   FreeMarker();
        Map<String, Object> maps = new HashMap<>();
        maps.put("leafletId" ,leaflet.getLeafletId());
        maps.put("headline" ,leaflet.getHeadline());
        maps.put("imgUrl" ,leaflet.getImgUrl());
        maps.put("heat" ,leaflet.getHeat());
        maps.put("summary" ,leaflet.getSummary());
        maps.put("detail" ,leaflet.getDetail());
        maps.put("comment" ,leaflet.getComment());
        maps.put("createTime" ,leaflet.getCreateTime());
        maps.put("updateTime" ,leaflet.getCreateTime());

        //装载数据模型
        model.setSiteId(leaflet.getSiteId());
        model.setChannelId("0");
        model.setTempletId(leaflet.getTempletId());
        model.setMaps(maps);
        return model;
    }

    private static final String regEx_script = "<#include"; // 定义script的正则表达式
    private static final String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
    private static final String regEx_html = ">"; // 定义HTML标签的正则表达式
    private static final String regEx_space = "\\s*|\t|\r|\n";// 定义空格回车换行符
    private static final String regEx_w = "<w[^>]*?>[\\s\\S]*?<\\/w[^>]*?>";//定义所有w标签

    /**
     * @param htmlStr
     * @return 删除Html标签
     * @author LongJin
     */
    public static String delHTMLTag(String htmlStr) {
        String a = htmlStr.replaceAll("<#include","");
       a =  htmlStr.replaceAll(">","");
        return a.trim(); // 返回文本字符串
    }

}
